//
//  LGOrderInformationView.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/3/14.
//  订单信息

#import "LGOrderInformationView.h"

@interface LGOrderInformationView()
/**   */
@property (nonatomic , strong)UIButton *titleBtn;
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UILabel *appointTime;
/**   */
@property (nonatomic , strong)UILabel *orderNumber;
/**   */
@property (nonatomic , strong)UILabel *orderTime;
/**   */
@property (nonatomic , strong)UILabel *priceLabel;

@end

@implementation LGOrderInformationView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.titleBtn];
        [self addSubview:self.baseView];
    }
    return self;
}


-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    NSString *type = LGNSString(dataDic[@"appointment_type"]);
//    NSString *
    if([type isEqualToString:@"4"]){
        //团队咨询
        [self.baseView addSubview:self.orderTime];
        [self.baseView addSubview:self.priceLabel];
        [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).offset(viewPix(46));
            make.left.equalTo(self).offset(viewPix(12));
            make.right.bottom.equalTo(self).offset(-viewPix(12));
            make.height.equalTo(@(viewPix(77)));
        }];
        [self.orderTime mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.baseView).offset(viewPix(10));
            make.left.equalTo(self.baseView).offset(viewPix(8));
            make.height.equalTo(@(viewPix(23)));
        }];
        [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.orderTime.mas_bottom).offset(viewPix(10));
            make.left.height.equalTo(self.orderTime);
        }];
        
        self.orderTime.attributedText = [self attributeWithTitle:@"订单时间" content:dataDic[@"create_time"]];
        self.priceLabel.attributedText = [self attributeWithTitle:@"支付金额" content:[NSString stringWithFormat:@"%@ 元",dataDic[@"total_amount"]]];
        
    }else if ([type isEqualToString:@"1"]){
        //线下门诊
        [self.baseView addSubview:self.appointTime];
        [self.baseView addSubview:self.orderTime];
        [self.baseView addSubview:self.priceLabel];
        [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).offset(viewPix(46));
            make.left.equalTo(self).offset(viewPix(12));
            make.right.bottom.equalTo(self).offset(-viewPix(12));
            make.height.equalTo(@(viewPix(103)));
        }];
        [self.appointTime mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.equalTo(self.baseView).offset(viewPix(8));
            make.height.equalTo(@(viewPix(23)));
        }];
        [self.orderTime mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.appointTime.mas_bottom).offset(viewPix(10));
            make.left.height.equalTo(self.appointTime);
        }];
        [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.orderTime.mas_bottom).offset(viewPix(10));
            make.left.height.equalTo(self.appointTime);
        }];
        self.appointTime.attributedText = [self attributeWithTitle:@"预约时间" content:[NSString stringWithFormat:@"%@ %@ %@号",dataDic[@"visit_date"],dataDic[@"start_time"],dataDic[@"appointment_no"]]];
        self.orderTime.attributedText = [self attributeWithTitle:@"订单时间" content:dataDic[@"create_time"]];
        self.priceLabel.attributedText = [self attributeWithTitle:@"支付金额" content:[NSString stringWithFormat:@"%@ 元",dataDic[@"total_amount"]]];
        
    }else if ([type isEqualToString:@"2"]||[type isEqualToString:@"6"]){
        //视频门诊 、 电话咨询
        [self.baseView addSubview:self.appointTime];
//        [self.baseView addSubview:self.orderNumber];
        [self.baseView addSubview:self.orderTime];
        [self.baseView addSubview:self.priceLabel];
        [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).offset(viewPix(46));
            make.left.equalTo(self).offset(viewPix(12));
            make.right.bottom.equalTo(self).offset(-viewPix(12));
            make.height.equalTo(@(viewPix(103)));
        }];
        [self.appointTime mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.equalTo(self.baseView).offset(viewPix(8));
            make.height.equalTo(@(viewPix(23)));
        }];
        [self.orderTime mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.appointTime.mas_bottom).offset(viewPix(10));
            make.left.height.equalTo(self.appointTime);
        }];
        [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.orderTime.mas_bottom).offset(viewPix(10));
            make.left.height.equalTo(self.appointTime);
        }];
        self.appointTime.attributedText = [self attributeWithTitle:@"预约时间" content:[NSString stringWithFormat:@"%@ %@ %@号",dataDic[@"visit_date"],dataDic[@"start_time"],dataDic[@"appointment_no"]]];
        if(dataDic[@"order"] && [LGNSString(dataDic[@"order"]) length]>6){
            [self.baseView addSubview:self.orderNumber];
            [self.orderNumber mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.appointTime.mas_bottom).offset(viewPix(10));
                make.left.equalTo(self.appointTime);
                make.height.equalTo(@(viewPix(23)));
            }];
            [self.orderTime mas_updateConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.appointTime.mas_bottom).offset(viewPix(43));
            }];
            [self.baseView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.equalTo(@(viewPix(136)));
            }];
            self.orderNumber.attributedText = [self attributeWithTitle:@"订单编号" content:dataDic[@"order"][@"order_sn"]];
        }
        self.orderTime.attributedText = [self attributeWithTitle:@"订单时间" content:dataDic[@"create_time"]];
        self.priceLabel.attributedText = [self attributeWithTitle:@"支付金额" content:[NSString stringWithFormat:@"%@ 元",dataDic[@"total_amount"]]];
        
    }else if ([type isEqualToString:@"3"]){
        //专家咨询
        [self.baseView addSubview:self.orderTime];
        [self.baseView addSubview:self.priceLabel];
        [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).offset(viewPix(46));
            make.left.equalTo(self).offset(viewPix(12));
            make.right.bottom.equalTo(self).offset(-viewPix(12));
            make.height.equalTo(@(viewPix(72)));
        }];
    
        [self.orderTime mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.equalTo(self.baseView).offset(viewPix(8));
            make.height.equalTo(@(viewPix(23)));
        }];
        [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.orderTime.mas_bottom).offset(viewPix(10));
            make.left.height.equalTo(self.orderTime);
        }];
        
        if(dataDic[@"order"] && [LGNSString(dataDic[@"order"]) length]>6){
            [self.baseView addSubview:self.orderNumber];
            [self.orderNumber mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.left.equalTo(self.baseView).offset(viewPix(8));
                make.right.equalTo(self.baseView).offset(-viewPix(3));
                make.height.equalTo(@(viewPix(23)));
            }];
            [self.orderTime mas_updateConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.baseView).offset(viewPix(41));
            }];
            [self.baseView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.equalTo(@(viewPix(105)));
            }];
            self.orderNumber.attributedText = [self attributeWithTitle:@"订单编号" content:dataDic[@"order"][@"order_sn"]];
        }
        self.orderTime.attributedText = [self attributeWithTitle:@"订单时间" content:dataDic[@"create_time"]];
        self.priceLabel.attributedText = [self attributeWithTitle:@"支付金额" content:[NSString stringWithFormat:@"%@ 元",dataDic[@"total_amount"]]];
        
    }else if ([type isEqualToString:@"5"]){
        //运动评估
        [self.baseView addSubview:self.appointTime];
        [self.baseView addSubview:self.orderTime];
        [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).offset(viewPix(46));
            make.left.equalTo(self).offset(viewPix(12));
            make.right.bottom.equalTo(self).offset(-viewPix(12));
            make.height.equalTo(@(viewPix(72)));
        }];
        [self.appointTime mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.equalTo(self.baseView).offset(viewPix(8));
            make.height.equalTo(@(viewPix(23)));
        }];
        [self.orderTime mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.appointTime.mas_bottom).offset(viewPix(10));
            make.left.height.equalTo(self.appointTime);
        }];

        self.appointTime.attributedText = [self attributeWithTitle:@"预约时间" content:[NSString stringWithFormat:@"%@ %@ %@号",dataDic[@"visit_date"],dataDic[@"start_time"],dataDic[@"appointment_no"]]];
        self.orderTime.attributedText = [self attributeWithTitle:@"订单时间" content:dataDic[@"create_time"]];
        
    }
}

-(NSMutableAttributedString *)attributeWithTitle:(NSString *)title  content:(NSString *)content{
    NSString *tempStr = [NSString stringWithFormat:@"%@  %@",title,content];
    NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc]initWithString:tempStr];
    [attrStr addAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithString:@"#333333"]} range:NSMakeRange(title.length, tempStr.length-title.length)];
    return attrStr;
}


-(UIButton *)titleBtn{
    if(!_titleBtn){
        _titleBtn = [UIButton buttonWithTitle:@"订单信息" titleFont:LGFontWeight(16, UIFontWeightMedium) textColor:@"#333333" imageName:@"订单详情-订单信息"];
        _titleBtn.frame = CGRectMake(viewPix(16), viewPix(12), viewPix(150), viewPix(22));
        _titleBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _titleBtn.titleEdgeInsets = UIEdgeInsetsMake(0, viewPix(4), 0, 0);
    }
    return _titleBtn;
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [[UIView alloc] init];
        _baseView.backgroundColor = [UIColor colorWithString:@"#F7F9FB"];
        _baseView.cornerRidus = 5;
    }
    return _baseView;
}

-(UILabel *)appointTime{
    if(!_appointTime){
        _appointTime = [UILabel lableWithText:@"预约时间：" colorString:@"#666666" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _appointTime;
}

-(UILabel *)orderNumber{
    if(!_orderNumber){
        _orderNumber = [UILabel lableWithText:@"订单编号：" colorString:@"#666666" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:2];
    }
    return _orderNumber;
}

-(UILabel *)orderTime{
    if(!_orderTime){
        _orderTime = [UILabel lableWithText:@"订单时间：" colorString:@"#666666" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _orderTime;
}

-(UILabel *)priceLabel{
    if(!_priceLabel){
        _priceLabel = [UILabel lableWithText:@"支付金额：" colorString:@"#666666" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _priceLabel;
}

@end
